﻿<template id="@(ViewBag.GetCompTemplate("form"))">
    <el-dialog v-model="visible" :width="500" :title="title" :destroy-on-close="true" :close-on-click-modal="false" :close-on-press-escape="false" draggable v-on:close="closed">
        <el-divider class="layout-page-form-top-border"></el-divider>
        <el-form ref="formRef" :rules="rules" :disabled="disabled" :model="record" :hide-required-asterisk="disabled" label-width="auto" label-suffix=" :">
            <el-form-item label="功能名称" prop="Title">
                <el-input v-model="record.Title"></el-input>
            </el-form-item>
            <el-form-item label="功能图标" prop="Icon">
                <single_icon_select v-model="record.Icon"></single_icon_select>
            </el-form-item>
            <el-form-item label="类型" prop="Type">
                <el-radio-group v-model="record.Type">
                    <el-radio-button value="power" label="可视权限"></el-radio-button>
                    <el-radio-button value="tools" label="功能按钮"></el-radio-button>
                    <el-radio-button value="table" label="表格按钮"></el-radio-button>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="功能键值" prop="Value">
                <el-input v-model="record.Value"></el-input>
            </el-form-item>
            <el-form-item label="扩展属性" prop="Attrs">
                <el-input v-model="record.Attrs"></el-input>
            </el-form-item>
            <el-form-item label="功能介绍" prop="Remark">
                <el-input v-model="record.Remark" type="textarea"></el-input>
            </el-form-item>
            <el-form-item label="排序" prop="Sequence">
                <el-slider v-model="record.Sequence" show-input :min="1"></el-slider>
            </el-form-item>
        </el-form>
        <template #footer>
            <el-button v-on:click="close">取消</el-button>
            <el-button type="primary" v-on:click="submit">确定</el-button>
        </template>
    </el-dialog>
</template>
<script type="text/javascript">
    var @(ViewBag.GetCompName("form")) = {
        template: "#@(ViewBag.GetCompTemplate("form"))", data() {
            return {
                path: "@(ViewBag.PagePath)",
                visible: false,
                title: null,
                rules: {
                    Title: [{ required: true, message: "请填写功能名称" }]
                },
                record: {},
                disabled: false
            }
        },
        methods: {
            reset(){
                this.record.Type = "power";
                this.record.Sequence = 99;
            },
            open(text, record){
                var that = this;
                that.title = text;
                if (record && record.Id) {
                    app.func.getEntity(`${that.path}/get`, record.Id, result => {
                        that.record = result.data;
                    });
                }
                else { that.reset(); }
                that.visible = true;
            },
            close(){
                this.visible = false;
            },
            closed(){
                this.title = null;
                this.record = {};
            },
            submit(){
                var that = this;
                that.$refs.formRef.validate(valid => {
                    if (valid) {
                        app.func.submit(`${that.path}/save`, that.record, result => {
                            that.close(); that.$emit("refresh");
                        });
                    }
                });
            }
        },
        mounted() { }
    };
</script>